package com.mall507.fivepeaks.activity.mine;

import android.os.Bundle;
import android.view.View;

import com.alibaba.android.arouter.launcher.ARouter;
import com.hzh.frame.ui.fragment.AbsRecyclerViewFM;
import com.hzh.frame.widget.xrecyclerview.RecyclerViewHolder;
import com.mall507.comn.model.MineRelease;
import com.mall507.comn.model.Original;
import com.mall507.fivepeaks.R;
import com.mall507.fivepeaks.widget.imageview.CircleImageView;
import com.mall507.fivepeaks.widget.imageview.ExpandImageView;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * 五峰原创
 */

public class MainReleaseTestRFM extends AbsRecyclerViewFM<MineRelease> {
    public final int ITEM_TYPE_ZHAOPIN = 0xff04;//招聘
    public final int ITEM_TYPE_QIUZHI = 0xff05;//求职
    public final int ITEM_TYPE_CHUZU = 0xff06;//出租
    public final int ITEM_TYPE_QIUZU = 0xff07;//求租
    public final int ITEM_TYPE_CHUSHOU = 0xff08;//出售
    public final int ITEM_TYPE_QIUGOU = 0xff09;//求购
    public final int ITEM_TYPE_ZHUANRANG = 0xff10;//转让
    public final int ITEM_TYPE_ERSHOU = 0xff11;//二手买卖
    List<String> listUrl;

    public static MainReleaseTestRFM newInstance(int type) {
        MainReleaseTestRFM myFragment = new MainReleaseTestRFM();
        Bundle bundle = new Bundle();
        bundle.putInt("type", type);
        myFragment.setArguments(bundle);
        return myFragment;
    }

    @Override
    public boolean setTitleIsShow() {
        return false;
    }

    @Override
    protected int setLayoutId() {
        return R.layout.fm_rv_main_original;
    }

    @Override
    protected String setHttpPath() {
        return "Me/getRelease";
    }

    @Override
    protected JSONObject setHttpParams() {
        JSONObject params = new JSONObject();
        try {
            params.put("type", getArguments().getInt("type"));
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return params;
    }

    @Override
    protected List<MineRelease> handleHttpData(JSONObject response) {
        List<MineRelease> list = new ArrayList<>();
        if (200 == response.optInt("code")) {
            JSONArray data = response.optJSONArray("data");
            if (data != null && data.length() > 0) {
                for (int i = 0; i < data.length(); i++) {
                    JSONObject object=data.optJSONObject(i);
                    JSONObject info = object.optJSONObject("info");
                    MineRelease model=new MineRelease();
                    model.setInfo_type(object.optString("info_type"));
                    model.setType(object.optString("type"));
                    model.setNid(object.optString("id"));

                    model.setTitle(object.optString("title"));
                    model.setAreaname(object.optString("areaname")); //地区名称
                    model.setPosttime(object.optString("posttime"));
//                    model.setXinzi(info.optString("xinzi"));
//                    model.setRenshu(info.optString("renshu"));
//                    model.setGongsi(info.optString("gongsi"));
//
                    model.setThumb(object.optString("thumb"));
//                    model.setXingbie(info.optString("xingbie"));
//                    model.setNianling(info.optString("nianling"));
//
//                    model.setXiaoqu(info.optString("xiaoqu"));
//                    model.setShi(info.optString("shi"));
                    model.setTing(info.optString("ting"));
//                    model.setWei(info.optString("wei"));
//                    model.setLeixing(info.optString("leixing"));
//
//                    model.setMianji(info.optString("mianji"));
//
//                    model.setZhuanranfei(info.optString("zhuanranfei"));
                    list.add(model);
                }
            }
        }
        return list;
    }


    @Override
    protected int setItemLayoutId(int viewType) {
        return R.layout.item_rv_main_original;
    }

    @Override
    protected void bindItemData(RecyclerViewHolder holder, int position, final MineRelease model) {
//        ((ExpandImageView) holder.getView(R.id.image)).setImageURI(model.getCover_img());
        holder.setText(R.id.title,model.getTitle());
//        ((CircleImageView) holder.getView(R.id.head)).setImageURI(model.getHeadImage());
//        holder.setText(R.id.nice,model.getNice());
//        holder.setText(R.id.time,model.getTime());
//        holder.setText(R.id.content,model.getContent());
//        holder.setText(R.id.browseNumber,model.getBrowseNumber()+"人浏览");
//        holder.setText(R.id.lickNumber,model.getLickNumber());
        
//        holder.setOnItemClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View view) {
//                ARouter.getInstance()
//                        .build("/comn/ComnCultureItemInfoRUI")
//                        .withString("id", model.getNid())
//                        .withString("commentRequestPath","Comment/getOriginalComment")
//                        .withString("headRequestPath","Original/getOriginDetail")
//                        .withString("type","5")
//                        .withString("collection_count",model.getLickNumber())
//                        .navigation();
//            }
//        });
        
    }

    /**
     * 绑定banner数据
     */
    private void bindTopBannerData(List<String> listUrl) {
        
    }
}
